Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datastore(fix): Fixes previous PR which was inadvertently creating multiple websockets. #2719

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

tylerjroach
Copy link
Member

  • PR title and description conform to Pull Request guidelines.

Issue #, if available:

Description of changes:

Continuation of #2718

The previous PR was inadvertently creating multiple websockets. This is because the websocket lock had a check
if (webSocketListener == null || webSocketListener.isDisconnectedState()) which would create a new ws. Because we were rapidly sending, every subscription request was in a disconnected state.

This PR waits for the ws connection to open, before it adds the subscriptions

Additionally, I also discovered that disconnecting the websocket takes too long due to the same issue we observed in #2718 with the creation of the subscriptions.

How did you test these changes?
(Please add a line here how the changes were tested)

Documentation update required?

  • No
  • Yes (Please include a PR link for the documentation update)

General Checklist

  • Added Unit Tests
  • Added Integration Tests
  • Security oriented best practices and standards are followed (e.g. using input sanitization, principle of least privilege, etc)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@tylerjroach tylerjroach requested a review from a team as a code owner February 16, 2024 21:55
@codecov-commenter
Copy link

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (1804551) 42.85% compared to head (6f9f31b) 42.87%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2719      +/-   ##
==========================================
+ Coverage   42.85%   42.87%   +0.01%     
==========================================
  Files         905      905              
  Lines       29098    29099       +1     
  Branches     4142     4142              
==========================================
+ Hits        12471    12476       +5     
+ Misses      15269    15267       -2     
+ Partials     1358     1356       -2     

Copy link
Member

@mattcreaser mattcreaser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I was concerned because we would lose the ability to have multiple threads waiting for the connection concurrently, but that isn't a concerned since waitForConnection will return immediately after connected - so threads are simply waiting for webSocket lock instead, and there's no impact to throughput.

Removal of synchronize on releaseSubscriptions also looks good, and allows releasing multiple subscriptions in parallel to speed up the shutdown process.

I think my main question is whether the isDisconnected() check even makes sense while establishing subscriptions. If the socket is closed due to failure then error handling should have already been in progress, otherwise if it was a graceful close then webSocketListener will already be null. Recognize that isn't really part of this PR but something worth thinking about.

@mattcreaser
Copy link
Member

mattcreaser commented Feb 17, 2024

👍 Looks good in testing. Subscription establishment is much faster than in 2.14.10 (and the improvement is more significant the more models you have) and the hidden asynchronous portion of Datastore.stop() is now also much faster. I also tested the "stop->start" scenario and that worked as expected as well.

@tylerjroach tylerjroach enabled auto-merge (squash) February 19, 2024 14:11
@tylerjroach tylerjroach merged commit 14acc3b into main Feb 19, 2024
4 checks passed
@tylerjroach tylerjroach deleted the tjroach/ds-subscription-optimization-pt2 branch February 19, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants